package leetcode.datastructure.hash;

import common.bean.TreeNode;

import java.util.ArrayList;
import java.util.List;


public class Program383WordAContainWordBAllCharacter {

    public Program383WordAContainWordBAllCharacter() {
    }
    public boolean canConstruct(String ransomNote, String magazine) {
        if (ransomNote.length() == 0) {
            return true;
        }
        if (magazine.length() == 0) {
            return false;
        }
        if (ransomNote.length() > magazine.length()) {
            return false;
        }
        int[] chars = new int[26];
        for (int i = 0; i < magazine.length(); i++) {
            chars[magazine.charAt(i) - 'a']++;
        }
        for (int i = 0; i < ransomNote.length(); i++) {
            int index = ransomNote.charAt(i) - 'a';
            chars[index]--;
            if (chars[index] < 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {

        Program383WordAContainWordBAllCharacter program = new Program383WordAContainWordBAllCharacter();
//        String ransomNote = "aa";
//        String magazine = "ab";
        String ransomNote = "aa";
        String magazine = "aab";
        System.out.println(program.canConstruct(ransomNote, magazine));
    }
}
